package com.defangit.award.extend.wxmp;

import com.defangit.award.extend.point.OrmMappingEp;
import com.defangit.award.extend.point.WinningInfoListener;
import com.defangit.award.extend.wxmp.config.YkWxmpConfig;
import com.defangit.award.extend.wxmp.config.ZmWxmpConfig;
import com.defangit.award.extend.wxmp.rest.WxmpUserInfoResource;
import com.defangit.award.extend.wxmp.rest.WxmpUserResource;
import com.defangit.openapis.wechat.mp.Wechat;
import com.defangit.openapis.wechat.mp.rest.WxmpResource;
import com.laogen.plugins.PluginEntry;
import com.laogen.plugins.PluginManager;
import laogen.io.ConfigNodes;
import laogen.util.UniqueNoConfigNodes;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by zhangfagen on 2019/1/9.
 */
public class WxmpPluginEntry implements PluginEntry {

    public static final Map<String,WxmpConfig> wechatMp=new HashMap<>();
    static{
        wechatMp.put("zm",new WxmpConfig("zm")
                .setAppId("wx6971f11ba837964d")
                .setSecret("4acbd0ea54923072d83bbe06177d9da5")
                .setToken("jlg9M6q02SL1nazHP7V9euiAxUkkBP3A")
        );
        wechatMp.put("yk",new WxmpConfig("yk")
                .setAppId("wx7abed5536b7c9c96")
                .setSecret("cc7d54f7d537e7f0dfaa132dcb335f11")
                .setToken("ziiOKRcf7vxbxymoMyPyuGOImkD5nCjX")
        );
    }

    public static Wechat getWechat(String gh){
        WxmpConfig cfg=wechatMp.get(gh);
        return Wechat.getInstance(cfg.getAppId(),cfg.getSecret());
    }

    @Override
    public void start() {
        UniqueNoConfigNodes nos=new UniqueNoConfigNodes("tenpay.gift","企业红包")
                .setPrefix("ZG")
                .setTimePattern("yyyyMMdd")
                .setSizePerLoop(100);
        ConfigNodes.registerConfigNodes(nos);
        WxmpResource.registerConfig("zm",new ZmWxmpConfig());
        WxmpResource.registerConfig("yk",new YkWxmpConfig());

        PluginManager.getInstance().registerListener(OrmMappingEp.class,new WxmpMappings());
        PluginManager.getInstance().registerListener(WinningInfoListener.class,new WxmpWinningInfoListener());
        PluginManager.getInstance().registerClass("rest", WxmpResource.class);
        PluginManager.getInstance().registerClass("rest", WxmpUserResource.class);
        PluginManager.getInstance().registerClass("rest", WxmpUserInfoResource.class);
    }


}
